home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / svgabg55 / svgautil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-25  |  6.7 KB  |  243 lines

  1. /************************************************/
  2. /*                         */
  3. /*          SuperVGA utility routines        */
  4. /*        Copyright (c) 1991        */
  5. /*        Jordan Hargraphix Software        */
  6. /*                        */
  7. /************************************************/
  8.  
  9. #include <dos.h>
  10. #include <graphics.h>
  11. #include "svgautil.h"
  12. #include "svga16.h"
  13. #include "svga256.h"
  14. #include "svga32k.h"
  15. #include "svga64k.h"
  16. #include "svgatc.h"
  17. #include "svgas3.h"
  18. #include "twk16.h"
  19. #include "twk256.h"
  20.  
  21. /************************************************************************/
  22. /*                                    */
  23. /*             Enhanced color setting functions            */
  24. /*                                    */
  25. /* These functions are used to set the colors for the 32k/64k/TrueColor */
  26. /* modes, as the BGI kernel can only handle 8-bit color values.        */
  27. /*                                    */
  28. /************************************************************************/
  29.  
  30. /********************************************************/
  31. /* long RGB(char rVal, char gVal, char bVal);       */
  32. /*                               */
  33. /* Purpose: Returns the color value for a R,G,B triple  */
  34. /*    based on the current graphics mode.        */
  35. /*                            */
  36. /* Input:                        */
  37. /*    char rVal - Red value   [0..255]        */
  38. /*    char gVal - Green value [0..255]        */
  39. /*    char bVal - Blue value  [0..255]        */
  40. /*                            */
  41. /* Returns:                        */
  42. /*     long - Color value for this mode.        */
  43. /*                            */
  44. /********************************************************/
  45. long RGB(char rVal, char gVal, char bVal)
  46. {
  47.     __rColor xColor;
  48.  
  49.     switch(getmaxcolor()) {
  50.       case 32767: 
  51.     xColor.c15.rVal = (rVal >> 3) & 0x1F;
  52.     xColor.c15.gVal = (gVal >> 3) & 0x1F;
  53.     xColor.c15.bVal = (bVal >> 3) & 0x1F;
  54.     break;
  55.       case 65535: 
  56.     xColor.c16.rVal = (rVal >> 3) & 0x1F;
  57.     xColor.c16.gVal = (gVal >> 2) & 0x1F;
  58.     xColor.c16.bVal = (bVal >> 3) & 0x1F;
  59.     break;
  60.     case 16777:
  61.     xColor.c24.rVal = rVal;
  62.     xColor.c24.gVal = gVal;
  63.     xColor.c24.bVal = bVal;
  64.     break;
  65.     }
  66.     return (xColor.cval);
  67. }
  68.  
  69. /****************************************************************/
  70. /* long RealDrawColor(long color);                  */
  71. /*                                   */
  72. /* Purpose: Sets the current drawing color for HC/TC modes.    */
  73. /*    Used for 'setcolor'                    */
  74. /*                                */
  75. /* Input:                            */
  76. /*    long color - Color value                */
  77. /*                                */
  78. /* Returns:                            */
  79. /*    long - Color value                    */
  80. /*                                */
  81. /****************************************************************/
  82. long RealDrawColor(long color)
  83. {
  84.     __rColor xColor;
  85.  
  86.     xColor.cval = color;
  87.     /* Do color set hacks for hicolor/truecolor modes */
  88.     switch(getmaxcolor()) {
  89.       case 32767:
  90.     setrgbpalette(1024,xColor.c15.rVal,xColor.c15.gVal,xColor.c15.bVal);
  91.     break;
  92.       case 65535:
  93.     setrgbpalette(1024,xColor.c16.rVal,xColor.c16.gVal,xColor.c16.bVal);
  94.     break;
  95.       case 16777:
  96.     setrgbpalette(1024,xColor.c24.rVal,xColor.c24.gVal,xColor.c24.bVal);
  97.     break;
  98.     };
  99.     return color;
  100. }
  101.  
  102. /****************************************************************/
  103. /* long RealFillColor(long color);                  */
  104. /*                                   */
  105. /* Purpose: Sets the current fill color for HC/TC modes.    */
  106. /*    Used for 'setfillstyle' and 'setfillpattern'        */
  107. /*                                */
  108. /* Input:                            */
  109. /*    long color - Color value                */
  110. /*                                */
  111. /* Returns:                            */
  112. /*    long - Color value                    */
  113. /*                                */
  114. /****************************************************************/
  115. long RealFillColor(long color)
  116. {
  117.     __rColor xColor;
  118.  
  119.     xColor.cval = color;
  120.     /* Do color set hacks for hicolor/truecolor modes */
  121.     switch(getmaxcolor()) {
  122.       case 32767:
  123.     setrgbpalette(1025,xColor.c15.rVal,xColor.c15.gVal,xColor.c15.bVal);
  124.     break;
  125.       case 65535:
  126.     setrgbpalette(1025,xColor.c16.rVal,xColor.c16.gVal,xColor.c16.bVal);
  127.     break;
  128.       case 16777:
  129.     setrgbpalette(1025,xColor.c24.rVal,xColor.c24.gVal,xColor.c24.bVal);
  130.     break;
  131.     };
  132.     return color;
  133. }
  134.  
  135. /****************************************************************/
  136. /* long RealColor(long color);                      */
  137. /*                                   */
  138. /* Purpose: Sets the current color for HC/TC modes.        */
  139. /*    Used for 'putpixel' and 'floodfill'            */
  140. /*                                */
  141. /* Input:                            */
  142. /*    long color - Color value                */
  143. /*                                */
  144. /* Returns:                            */
  145. /*    long - Color value                    */
  146. /*                                */
  147. /****************************************************************/
  148. long RealColor(long color)
  149. {
  150.     __rColor xColor;
  151.  
  152.     xColor.cval = color;
  153.     /* Do color set hacks for hicolor/truecolor modes */
  154.     switch(getmaxcolor()) {
  155.       case 32767:
  156.     setrgbpalette(1026,xColor.c15.rVal,xColor.c15.gVal,xColor.c15.bVal);
  157.     break;
  158.       case 65535:
  159.     setrgbpalette(1026,xColor.c16.rVal,xColor.c16.gVal,xColor.c16.bVal);
  160.     break;
  161.       case 16777:
  162.     setrgbpalette(1026,xColor.c24.rVal,xColor.c24.gVal,xColor.c24.bVal);
  163.     break;
  164.     };
  165.     return color;
  166. }
  167.  
  168. /* Getvgapalette16 gets the entire 16 color palette */
  169. /* PalBuf contains RGB values for all 16 colors     */
  170. /* R,G,B values range from 0 to 63                */
  171. /* Usage:                         */ 
  172. /*  DacPalette16 dac16;                             */
  173. /*                            */
  174. /*  getvgapalette(&dac16);                */
  175. void getvgapalette16(DacPalette16 *PalBuf)
  176. {
  177.   struct REGPACK reg;
  178.  
  179.   reg.r_ax = 0x1017;
  180.   reg.r_bx = 0;
  181.   reg.r_cx = 16;
  182.   reg.r_es = FP_SEG(PalBuf);
  183.   reg.r_dx = FP_OFF(PalBuf);
  184.   intr(0x10,®);
  185. }
  186.  
  187. /* Getvgapalette256 gets the entire 256 color palette */
  188. /* PalBuf contains RGB values for all 256 colors      */
  189. /* R,G,B values range from 0 to 63                  */
  190. /* Usage:                          */
  191. /*  DacPalette256 dac256;                  */
  192. /*                              */
  193. /* getvgapalette256(&dac256);                  */
  194. void getvgapalette256(DacPalette256 *PalBuf)
  195. {
  196.   struct REGPACK reg;
  197.  
  198.   reg.r_ax = 0x1017;
  199.   reg.r_bx = 0;
  200.   reg.r_cx = 256;
  201.   reg.r_es = FP_SEG(PalBuf);
  202.   reg.r_dx = FP_OFF(PalBuf);
  203.   intr(0x10,®);
  204. }
  205.  
  206. /* Setvgapalette16 sets the entire 16 color palette */
  207. /* PalBuf contains RGB values for all 16 colors     */
  208. /* R,G,B values range from 0 to 63                */
  209. /* Usage:                         */ 
  210. /*  DacPalette16 dac16;                             */
  211. /*                            */
  212. /*  setvgapalette(&dac16);                */
  213. void setvgapalette16(DacPalette16 *PalBuf)
  214. {
  215.   struct REGPACK reg;
  216.  
  217.   reg.r_ax = 0x1012;
  218.   reg.r_bx = 0;
  219.   reg.r_cx = 16;
  220.   reg.r_es = FP_SEG(PalBuf);
  221.   reg.r_dx = FP_OFF(PalBuf);
  222.   intr(0x10,®);
  223. }
  224.  
  225. /* Setvgapalette256 sets the entire 256 color palette */
  226. /* PalBuf contains RGB values for all 256 colors      */
  227. /* R,G,B values range from 0 to 63                  */
  228. /* Usage:                          */
  229. /*  DacPalette256 dac256;                  */
  230. /*                              */
  231. /* setvgapalette256(&dac256);                  */
  232. void setvgapalette256(DacPalette256 *PalBuf)
  233. {
  234.   struct REGPACK reg;
  235.  
  236.   reg.r_ax = 0x1012;
  237.   reg.r_bx = 0;
  238.   reg.r_cx = 256;
  239.   reg.r_es = FP_SEG(PalBuf);
  240.   reg.r_dx = FP_OFF(PalBuf);
  241.   intr(0x10,®);
  242. }
  243.